let test = [1,2,[3,4,[5,6]],7,8]
Array.prototype.sx_flat = function (deep=1) {
    let arr = this
    while (arr.some(item => Array.isArray(item))&&deep>0) {
        arr = [].concat(...arr)
        deep--
    }
    return arr
}
// console.log(...test);
// console.log([].concat(...test));
console.log(test.sx_flat(3));